package Phase1Tests;
import java.io.IOException;
import java.util.*;

import junit.framework.*;
import junit.textui.*;
import Phase1.*;
public class testCommunication extends TestCase
{
	
	private final int DEFAULT_SERVER_PORT = 3000;
	private final int DEFAULT_CLIENT_PORT = 3001;
	
	public static void main(String[] args)
	{

		TestRunner.run(testCommunication.class); 

	}
	@SuppressWarnings("unchecked")
	public void testEmptyCollection() 
	{
		Collection<?> collection = new ArrayList();
		assertTrue(collection.isEmpty());
		
	}
	public void testServerRun()
	{
		Server server = new Server();
		server.start();
		assertTrue(server instanceof Server);
		assertTrue(server instanceof Thread);
	//	assertTrue(false);
		server.done();
	}
	
	public void testStringMessage()
	{
		Server server = new Server();
		server.start();
		String t = new String("here is the data");
		try 
		{ 
			assertTrue(t.equals(Client.sendData("localhost", 3001, t))); 
		} catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		catch (ClassNotFoundException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		server.done();
		 
	}
	public void testNullMessage()
	{
		Server server = new Server();
		server.start();
		String t = new String("here is the data");
		try 
		{ 
			assertTrue(!t.equals(Client.sendData("localhost", 3002, null)));
		} catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		server.done();
	}
	public void testServerHalt()
	{
		Server server = new Server();
		server.start();
		try 
		{
			Client.setLinkToServer("localhost", 3001);
		} catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (ClassNotFoundException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		server.done();
		
	}

	public void testWarp()
	{
		/*Command c=new Command();
		int r=1;
		double l=34344.435;
		int[] w={1,34,2,3,5};
		Object t=w;
		int[] f=(int[])t;
		 c.warp(r);
		System.out.println(t instanceof Object);
		System.out.println(f instanceof Object);

		System.out.println(w.getClass().isArray());
		System.out.println("---"+f.toString()  );*/
	} 
}
